/*
 * @Description:
 * @Author: wangfuwei
 * @Date: 2020-12-08 21:28:16
 * @LastEditors: wangfuwei
 * @LastEditTime: 2021-04-22 20:07:45
 * @FilePath: /horizon-frontend/src/router/index.js
 */
import Vue from "vue";
import Router from "vue-router";
import { constantRouterMap } from "./config";

/**
 * 重写路由的push方法
 * 解决相同路由跳转时报错
 */
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};

Vue.use(Router);

const router = new Router({
  mode: "history",
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap,
});

export default router;
